﻿
using T.FAS.Runtime.DataAccess.Engine.ValidateChecker.Entity;

namespace T.FAS.Runtime.DataAccess.Engine
{
    #region Int类型校验

    public class IntValidateFactory : CommonFactory
    {
        public override IColumnValidater GetDataTypeValidater()
        {
            return new IntDataTypeValidater();
        }

        public override IColumnValidater GetLengthValidater()
        {
            return new IntLengthValidater();
        }
    }

    public class IntDataTypeValidater : IColumnDataTypeValidater
    {
        public ValidateCheckItem Validate(ValidateCheckItem item)
        {
            if (item.Result.IsStop)
                return item;

            var inputVal = item.InputValue.ToString();
            //数据类型验证
            if (!int.TryParse(inputVal, out int value))
            {
                item.Result.Flag = false;
                item.Result.IsStop = true;
                item.Result.Msg.Append(string.Format(ValidateConst.DataTypeErrorTemp, item.CheckElement.Name, inputVal, item.CheckElement.DataType));
            }
            else
            {
                item.ConvertValue = value;
            }
            return item;
        }
    }

    public class IntLengthValidater : IColumnLengthValidater
    {
        public ValidateCheckItem Validate(ValidateCheckItem item)
        {
            return item;    //int不做长度校验
        }
    }

    #endregion
}
